package org.liquidByte.trafficMustang.androidApp.services.proxy;

import org.liquidByte.trafficMustang.androidApp.LocationTracker;
import org.liquidByte.trafficMustang.androidApp.proxy.Proxy;
import org.liquidByte.trafficMustang.androidApp.proxy.ProxyRuntimeException;
import org.liquidByte.trafficMustang.androidApp.proxy.RemoteException;
import org.liquidByte.trafficMustang.androidApp.services.RastreamentoService;
import org.liquidByte.trafficMustang.androidApp.services.dto.LocalizacaoDTO;
import org.liquidByte.trafficMustang.androidApp.services.dto.UsuarioDTO;

import android.location.Location;

public class RastreamentoProxy extends Proxy implements RastreamentoService {
	
	@Override
	public void update(LocalizacaoDTO localizacao) throws ProxyRuntimeException, RemoteException {
		this.invoke("rastreamento/update", localizacao);
	}

	@Override
	public LocalizacaoDTO getLocation(UsuarioDTO usuario) throws RemoteException, ProxyRuntimeException {
		return this.invoke("rastreamento/getLocation", LocalizacaoDTO.class, usuario);
	}

	@Override
	public void update() throws RemoteException, ProxyRuntimeException {
		Location location = LocationTracker.getInstance().getLastKnown();
		LocalizacaoDTO dto = LocalizacaoDTO.fromLocation(location);
		this.update(dto);
	}
}
